<template>
	<div class="base-content page-content classRoomInfo">
		<ul class="base-item-tab">
			<li>
				<router-link to="/BaseSetting/teachTime">教学时间</router-link>
			</li>
			<li>
				<router-link to="/BaseSetting/courseInfo">课程信息</router-link>
			</li>
			<li>
				<router-link to="/BaseSetting/teacher">教师信息</router-link>

			</li>
			<li  v-if="classType==2">
				<router-link to="/BaseSetting/classRoomInfo" class="active">教室信息</router-link>
			</li>
					
			<li v-if="tnId == 66">
				<router-link to="/BaseSetting/courseAndTeach">教师及课时分配</router-link>
			</li>

		</ul>
		<div id="classNum">
			<div class="title-2">
				<span class="txt-t"><span class="grade-now">{{gradeName}}</span>教室信息</span>
			</div>
			<div class="scheduling-course">
				<p style="font-size: 14px;"><span class="grade-now">{{gradeName}}</span>行政班数量： <span id="class-number">{{bizData.admNumber}}</span></p>
				<label for="optional-class"> <em>*</em>可排课教室数量 <input type="text" v-model="scheduleNumber" id="optional-class" classroomid="392"> </label>
				<p class="warm-tip">提醒：可排教室数量不能小于行政班的班级数量。</p>
			</div>
			<el-tooltip :manual="true" :value="saveBtn" class="item" effect="dark" content="可排教室数量不能小于行政班的班级数量" placement="right">

				<button @click="saveClassNum()" class="btn-save-base" id="save-class" style="margin-top: 20px">保存</button>
			</el-tooltip>

		</div>
	</div>
</template>

<script>
	import utils from '@/assets/js/urlConfig.js'
	export default {
		props:['tnId'],
		data() {
				return {

					bizData: {
						"admNumber": "",
						"sum": "",
						"classRoomId": ""
					},
					scheduleNumber: '',
					saveBtn: false,
					defultNum: '',
					taskId: '',
					gradeName:'初一年级',
					classType:0

				}
			},
			mounted() {
				this.getClassRoomInfo();
			},
			methods: {
				saveClassNum() {

					if(this.scheduleNumber < this.bizData.admNumber) {

						this.saveBtn = true;
						setTimeout(() => {
							this.saveBtn = false;
						}, 2000);
						return;

					} else {

						this.saveBtn = false;
						this.$http.post(utils.UrlConfig.updateClassRoom + "&taskId=" + this.taskId + "&classRoomId=" + this.bizData.classRoomId + '&scheduleNumber=' + this.scheduleNumber)
							.then(res => {

								res = res.data;

								if(res.rtnCode === "0000000") {
									this.$message({
										message: '保存成功！',
										type: 'success'
									});

								} else {
									this.$message.error(res.msg);
								}

							}).catch(error => {
								console.log(error)
							})
					}
				},
				getClassRoomInfo() {
					this.taskId = sessionStorage.getItem('taskId');
					this.gradeName = sessionStorage.getItem('gradeName');
					this.classType = sessionStorage.getItem('classType');
					//字符串转为数值
					if(typeof(this.classType)=='string'){
						this.classType = Number(this.classType)
					}
					
					this.$http.get(utils.UrlConfig.getConfigRooms + '&taskId=' + this.taskId)
						.then(res => {

							res = res.data;
							
							if(res.rtnCode === "0000000") {
								this.scheduleNumber = res.bizData.sum;
								//this.scheduleNumber = res.bizData.admNumber;
								this.bizData = res.bizData;

							} else {
								this.$message.error(res.msg);
							}

						}).catch(error => {
							console.log(error)
						})
				}
			}
	}
</script>
<style>
	.classRoomInfo .base-item-tab {
		padding-bottom: 7px;
	}
	
	.classRoomInfo {
		padding-left: 0px;
	}
	
	.scheduling-course label em {
		color: #CB171D;
	}
	
	
	.classRoomInfo .base-item-tab li+li+li a {
		border-right: 1px solid #D8D8D8!important;
	}
	.classRoomInfo .base-item-tab li:last-child a {
		border-right: 0 !important;
	}
</style>